package com.juli.school.app.controller.module;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.juli.school.dao.entity.Pub;
import com.juli.school.service.bo.RecBo;
import com.juli.school.service.bo.SmartBo;
import com.juli.school.service.enums.EnumModule;
import com.juli.school.service.impl.RecService;
import com.juli.school.service.impl.SmartService;
import com.juli.school.utils.core.model.CommonResp;
import com.juli.school.utils.core.model.ListResp;
import com.juli.school.utils.core.model.PageResp;

/**
 * @Description: 智力众筹控制器
 * @author: Eve
 * @date: 2017/9/8.
 */
@Controller
@RequestMapping("/smart")
public class SmartController {
	
	@Resource
	SmartService smartService;
	
	@Resource
	RecService recService;
	
	/**
	 * 添加一条智力众筹
	 * @param love
	 * @return
	 */
	@RequestMapping(value = "add", method = RequestMethod.POST)
	@ResponseBody CommonResp<String> add(SmartBo smartBo) {
		return smartService.add(smartBo);
	}
	
	/**
	 * 修改一条智力众筹
	 * @param love
	 * @return
	 */
	@RequestMapping(value = "update", method = RequestMethod.POST)
	@ResponseBody CommonResp<String> update(SmartBo smartBo) {
		return smartService.update(smartBo);
	}
	
	/**
	 * 删除一条智力众筹记录
	 * @param snStamp
	 * @return
	 */
	@RequestMapping("delete")
	@ResponseBody CommonResp<String> delete(String snStamp, String stuId) {
		return smartService.delete(snStamp, stuId);
	}

	@RequestMapping("listPage")
	@ResponseBody CommonResp<PageResp<Pub>> listPage(SmartBo smartBo) {
		return smartService.listPage(smartBo);
	}
	
	/**
	 * @Description: 增量查询信息列表
	 * @author gaoxiang
	 * @date 2017年9月16日 下午10:27:17
	 */
	@RequestMapping("/list")
	@ResponseBody CommonResp<ListResp<Pub>> list(SmartBo req) {
		return smartService.list(req);
	}
	
	@RequestMapping("detail")
	@ResponseBody CommonResp<SmartBo> detail(SmartBo smartBo) {
		return smartService.detail(smartBo);
	}

	@RequestMapping("detailer")
	public String detailer(SmartBo smartBo,ModelMap model){
		model.put("type", EnumModule.Smart);
		CommonResp<List<RecBo>> list = recService.list(smartBo.getSnStamp());
		model.put("recs", list.getData());
		model.put("obj",  smartService.detail(smartBo));
		return "/detail/index";
	}
}
